<template>
  <view>
    <view class="goods-item">
      <!-- 空标签只用于包裹容器 -->
      <!-- 左侧部分 -->
      <view class="goods-left">
        <image :src="goods.goods_small_logo || defaultPic" class="goods-img"></image>
      </view>
      <!-- 右侧部分 -->
      <view class="goods-right">
        <view class="goods-right-name">{{goods.goods_name}}</view>
        <view class="goods-right-info">
          <view class="goods-right-number">￥{{goods.goods_price | filterPrice}}</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "my-goods",
    props:{
      goods:{
        // 接收父组件传递过来的参数
        type:Object,
        default:{}
      }
    },
    // 过滤器函数的使用
    filters:{
      filterPrice(num){
        // 转换为数字，保留两位小数
       return Number(num).toFixed(2)
      }
    },
    data() {
      return {
        defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    }
  }
</script>

<style lang="scss">
  .goods-item {
    display: flex;
    padding: 10px 5px;
    border: 1px solid #f0f0f0;
    // justify-content: space-between;

    .goods-left {
      margin-right: 5px;

      .goods-img {
        width: 100px;
        height: 100px;
        display: block;
      }
    }

    .goods-right {
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .goods-right-name {
        font-size: 13px;
      }

      .goods-right-info {
        .goods-right-number {
          font-size: 16px;
          color: #c00000;
        }
      }
    }
  }
</style>
